function newCounter()
    local a = 0
    return function()
        a = a + 1
        return a
    end
end

c1 = newCounter()
print(c1())
print(c1())
print(c1())

c2 = newCounter()
print(c2())
print(c2())